'use strict';

var twoSum = function(nums, target) {
  const map = nums.reduce((prev, cur, idx) => {
      if (prev[cur] !== undefined && cur + cur === target) {
          prev[cur] = [prev[cur], idx];
      } else {
          prev[cur] = idx;
      }
      return prev;
  }, {});
  for(const key of Object.keys(map)) {
      const other = target - key;
      if (map[other]) {
          if (Array.isArray(map[other])) {
              return map[other];
          }
          return [map[key], map[other]];
      }
  }
  return null;
};


/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var threeSum = function(nums) {
  for(let i = 0; i < nums.length; i++) {
    const twos = twoSum([...nums.slice(0, i), ...nums.slice(i + 1)], 0 - nums[i]);
    console.log(nums[i]);
    console.log([]);  
  }
};

console.log(threeSum([-1,0,1,2,-1,-4]));